package com.demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.entity.Card;
import com.demo.mapper.CardMapper;
import com.demo.service.CardService;
import org.springframework.stereotype.Service;
import com.demo.util.MyPage;

import javax.annotation.Resource;

/**
 * (Card)表服务实现类
 *
 * @author Sakura
 * @since 2023-11-26 17:07:05
 */
@Service("cardService")
public class CardServiceImpl extends ServiceImpl<CardMapper, Card> implements CardService {
    @Resource
    private CardMapper cardMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Card queryById(Long id) {
        return this.cardMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pageNo    当前页
     * @param pageSize  数据大小
     * @param searchKey 查询关键字
     * @return 查询结果
     */
    @Override
    public MyPage<Card> queryByPage(Integer pageNo, Integer pageSize, String searchKey) {
        long total = this.cardMapper.count(searchKey);
        int start=(pageNo-1)*pageSize;
        return new MyPage<Card>(this.cardMapper.queryPage(start,pageSize,searchKey),total);
    }

    /**
     * 新增数据
     *
     * @param card 实例对象
     * @return 实例对象
     */

    /**
     * 修改数据
     *
     * @param card 实例对象
     * @return 实例对象
     */
    @Override
    public boolean updateById(Card card) {
        int result = this.cardMapper.updateById(card);
        return result > 0;
     }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.cardMapper.deleteById(id) > 0;
    }
}
